feat: integrate Zod schemas for opt-in runtime validation#126
Open
feat: integrate Zod schemas for opt-in runtime validation#126
Conversation
Add opt-in runtime validation using auto-generated Zod schemas from the OpenAPI spec. Validation is controlled via a new 'validate' option on Scope3ClientConfig: - false/undefined (default): no validation, zero overhead - true: validate both inputs and responses - 'input': validate request bodies only - 'response': validate API responses only Changes: - Add ValidateMode type and validation utilities (src/validation.ts) - Add schema registry mapping operations to Zod schemas (src/schemas/registry.ts) - Thread validate config through BaseAdapter interface to resources - Wire response validation into campaigns, reporting, sales-agents, bundles, and products resources - Wire input validation into sales-agents, bundles, and products - Add validation unit tests (14 new tests) - Export validateInput/validateResponse for consumer use Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wires the auto-generated Zod schemas (from #124) into the SDK's resource layer for opt-in runtime validation.
Usage
When enabled, invalid inputs throw
Scope3ApiError(400)and unexpected API response shapes throwScope3ApiError(502)with structured Zod validation details.Default is off — zero overhead for existing consumers.
Changes
src/validation.ts— Thin validation utility (validateInput,validateResponse, mode helpers)src/schemas/registry.ts— Hand-maintained mapping from resource operations to auto-generated Zod schemassrc/types/index.ts— Addvalidateoption toScope3ClientConfigsrc/adapters/base.ts— AddvalidatetoBaseAdapterinterfacesrc/adapters/rest.ts,src/adapters/mcp.ts— Threadvalidateconfig through adaptersDesign Decisions
brandDomainvs APIbrand)